package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import JDBC.DATABASE;
import VO.Admin;


public class AdminDao {
	/*
	 * 管理员是否存在
	 */
/*	public boolean userIsExist(String account1){
		Connection conn=DATABASE.getConnection();
		String sql="select * from admins where account=?";//
		try{
			PreparedStatement ps=conn.prepareStatement(sql);//
			ps.setString(1,account1);
			ResultSet rs=ps.executeQuery();//
			if(!rs.next()){
				System.out.print("keyong");
				return true;
			}
			rs.close();
			ps.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DATABASE.close(conn);
		}
		return false;
	}*/
	
	
	public Admin login(String account1,String password1){
		Admin ad=null;
		Connection conn=DATABASE.getConnection();
		String sql="select * from admins where account=? and password=? ";
		try{
			PreparedStatement ps=conn.prepareStatement(sql);
			ps.setString(1,account1);
			ps.setString(2,password1);
			ResultSet rs=ps.executeQuery();
			if(rs.next()){
				System.out.print("3");
				ad=new Admin();
				ad.setAccount(rs.getString("account"));
				ad.setPassword(rs.getString("password"));
				ad.setTele(rs.getString("tele"));
			}
			rs.close();
			ps.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DATABASE.close(conn);
		}		
		return ad;
	}
}
